package com.xu.config;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        //登陆成功应有用户的session

        Object user = request.getSession().getAttribute("userid");
        if (user==null)
        {
            request.setAttribute("msg5", "没有权限，请先登录");
            request.getRequestDispatcher("/toLogin").forward(request,response);
            return false;
        }
        else if (!user.toString().equals("1"))
        {
            request.setAttribute("msg7", "没有权限");
            request.getRequestDispatcher("/toLogin").forward(request,response);
            return false;
        }
        return true;
    }
}
